<style lang="scss">
.back-container {
  .el-table {
    height: calc(100vh - 260px)!important;
    margin-bottom: 14px;
  }
  .paste-btn-div {
    margin-top: 5px;
    text-align: center;
  }
  .gdxx-div {
    outline: 1px dotted #cccccc;
    padding-top: 7px;
    margin-top: 7px;
  }
}
</style>

<template>
  <!-- 工单维护-已下发 -->
  <el-container class="back-container">
    <!-- 顶栏容器 -->
    <el-header>
      <!-- 查询框 -->
      <div class="search-box">
        <div class="conditions-box">
          <div class="conditions-item">年度:
            <el-select
              v-model="pageParam.condition.govYear"
              size="small"
              :clearable="true"
              placeholder="请选择年度"
              @change="doSearch"
              style="width: 160px;"
            >
              <el-option
                v-for="(item, index) in yearList"
                :key="index"
                :label="item"
                :value="item"
              ></el-option>
            </el-select>
          </div>
          <div class="conditions-item">
            工单编号:
            <el-input
              v-model="pageParam.condition.code"
              size="small"
              :clearable="true"
              placeholder="请输入工单编号"
              style="width: 160px;"
            ></el-input>
          </div>
          <div class="conditions-item">
            工单内容:
            <el-input
              v-model="pageParam.condition.content"
              size="small"
              :clearable="true"
              placeholder="请输入内容关键字"
              style="width: 160px;"
            ></el-input>
          </div>
          <div class="conditions-item">
            工单来源:
            <el-select
              v-model="pageParam.condition.sourceId"
              size="small"
              :clearable="true"
              placeholder="请选择工单来源"
              @change="doSearch"
              style="width: 160px;"
            >
              <el-option
                v-for="item in sourceList"
                :key="item.lyid"
                :label="item.lymc"
                :value="item.lyid"
              ></el-option>
            </el-select>
          </div>
          <div class="conditions-item">
            执行处室:
            <el-select
              v-model="pageParam.condition.deptId"
              size="small"
              :clearable="true"
              placeholder="请选择执行处室"
              @change="doSearch"
              style="width: 160px;"
            >
              <el-option
                v-for="item in deptList"
                :key="item.bmid"
                :label="item.bmjc"
                :value="item.bmid"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div class="search-btn">
          <el-button
            size="small"
            icon="el-icon-search"
            plain
            @click="doSearch"
            :loading="loadingTable"
          >查询</el-button>
        </div>
      </div>
    </el-header>
    <!-- 主要区域容器 -->
    <el-main>
      <el-table
        @row-dblclick="handledbClick"
        :data="tableItem.list"
        stripe
        border
        :height="tableHeight"
        v-loading="loadingTable"
      >
        <el-table-column prop="code" label="工单编号" align="left" show-overflow-tooltip></el-table-column>
        <el-table-column prop="sourceName" label="来源系统" align="center" width="160"></el-table-column>
        <el-table-column prop="cateName" label="工单类别" align="center" width="160"></el-table-column>
        <el-table-column prop="deptName" label="执行处室" align="center" width="260"></el-table-column>
        <el-table-column prop="repeated" label="重复件" align="center" width="120">
          <template slot-scope="scope">
            <i v-if="scope.row.repeated=== 1" class="el-icon-refresh" style="color: red; font-size: 16px;"></i>
            <i v-else class="el-icon-refresh" style="color: grey; font-size: 16px;"></i>
          </template>
        </el-table-column>
        <el-table-column prop="important" label="紧急件" align="center" width="120">
          <template slot-scope="scope">
            <i v-if="scope.row.important=== 1" class="el-icon-star-off" style="color: red; font-size: 16px;"></i>
            <i v-else class="el-icon-star-off" style="color: grey; font-size: 16px;"></i>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="unsatisfy" label="不满意" align="center" width="80">
          <template slot-scope="scope">
            <i v-if="scope.row.unsatisfy=== 1" class="el-icon-bell" style="color: red; font-size: 16px;"></i>
            <i v-else class="el-icon-bell" style="color: grey; font-size: 16px;"></i>
          </template>
        </el-table-column> -->
        <el-table-column
          prop="limitTime"
          label="处理时限"
          align="center"
          width="220"
          :formatter="formatLimitDate"
        ></el-table-column>
        <el-table-column
          prop="backTime"
          label="退回时间"
          align="center"
          width="220"
          :formatter="formatBackDate"
        ></el-table-column>
        <el-table-column prop="dqzt" label="当前状态" align="center" width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.dqzt=== 2" style="color: #F56C6C;">待分发</span>
            <span v-else-if="scope.row.dqzt=== 3" style="color: #E6A23C;">待办理</span>
            <span v-else-if="scope.row.dqzt=== 4" style="color: #409EFF;">已办理</span>
            <span v-else-if="scope.row.dqzt=== 5" style="color: #909399;">已退回</span>
            <span v-else-if="scope.row.dqzt=== 6" style="color: #67C23A;">已结束</span>
            <span v-else-if="scope.row.dqzt=== 7" style="color: #409EFF;">已办理审核</span>
            <span v-else-if="scope.row.dqzt=== 8" style="color: #909399;">退回待审核</span>
          </template>
        </el-table-column>
        <el-table-column prop="operations" label="操作" align="center" width="120">
          <template slot-scope="scope">
            <el-button
              v-for="(item, index) in scope.row.operationsModelList"
              :key="index"
              :type="item.type"
              plain
              size="mini"
              :icon="item.icon"
              v-bind:class="'operations-'+item.handleMethod"
              @click="operationClick(item.handleMethod, scope.row)"
            >{{item.label}}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="tableItem.pageNum"
        :page-size="tableItem.pageSize"
        :page-sizes="[20, 30, 50, 100]"
        :total="tableItem.total"
        layout="total, sizes, prev, pager, next, jumper"
        style="float: right;"
      ></el-pagination>
    </el-main>

    <!-- 已退回查看详情 -->
    <el-dialog
      title="工单查看"
      :visible.sync="dialogDetail"
      width="100%"
      :fullscreen="fullScreen"
      :before-close="dialogCloseFn"
      class="my_model_style"
    >
      <synthesize-detail v-if="dialogDetail" ref="synthesizeDetail" v-bind:wllzid="wllzid"></synthesize-detail>
    </el-dialog>
  </el-container>
</template>

<script>
import synthesizeDetail from '../synthesize/synthesize-detail'
export default {
  name: 'inquire-back',
  data () {
    return {
      dialogDetail: false,
      wllzid: '',
      // 年度列表
      yearList: [],
      // 来源列表
      sourceList: [],
      // 处室列表
      deptList: [],
      // 查询参数
      pageParam: {
        pageNum: 1,
        pageSize: 20,
        condition: {
          govYear: '',
          deptId: '',
          sourceId: '',
          code: '',
          content: ''
        }
      },
      loadingTable: false,
      // 表格高度
      tableHeight: -1,
      // 表格列表
      tableItem: {},
      // 查看详情
      dialogBackDetail: false,
      fullScreen: true
    }
  },
  methods: {
    // 页面处室话方法
    initFn () {
      this.getYearList()
      this.getSourceList()
      this.getDeptList()
      this.doSearch()
    },// 获取年度列表
    getYearList() {
      this.$axios.post(this.$api.common.yearList).then(rs => {
        if (rs) {
          this.yearList = rs
          // this.pageParam.condition.govYear = rs[0]
        }
      })
    },
    // 获取来源列表
    getSourceList () {
      this.$axios.post(this.$api.source.selector).then(rs => {
        if (rs) {
          this.sourceList = rs
        }
      })
    },
    // 获取责任处室
    getDeptList () {
      this.$axios.post(this.$api.dept.selector).then(rs => {
        if (rs) {
          this.deptList = rs
        }
      })
    },
    // 查询方法
    doSearch () {
      this.loadingTable = true
      this.getBackPage()
    },
    // 获取超期件分页列表
    getBackPage () {
      this.$axios.post(this.$api.inquire.backDept, this.pageParam).then(rs => {
        if (rs) {
          this.tableItem = rs
          this.loadingTable = false
        }
      })
    },
    // 分页
    handleSizeChange: function (size) {
      this.loadingTable = true
      this.pageParam.pageSize = size
      this.getBackPage()
    },
    // 分页
    handleCurrentChange: function (currentPage) {
      this.loadingTable = true
      this.pageParam.pageNum = currentPage
      this.getBackPage()
    },
    // 日期格式化
    formatLimitDate: function (row, column) {
      const _this = this
      var date = row.limitTime
      if (date === undefined) {
        return ''
      }
      return _this.$moment(date).format('YYYY年MM月DD日')
    },
    formatBackDate: function (row, column) {
      const _this = this
      var date = row.backTime
      if (date === undefined) {
        return ''
      }
      return _this.$moment(date).format('YYYY年MM月DD日 HH时mm分')
    },
    // 操作点击事件
    operationClick (method, row) {
      switch (method) {
        case 'detail':
          this.detailFn(row)
          break
      }
    },
    handledbClick (row, event, column) {
      this.detailFn(row)
    },
    // 查看
        detailFn: function (item) {
      this.wllzid = item.wllzid
      this.dialogDetail = true
    },
    dialogCloseFn: function () {
      this.wllzid = ''
      this.dialogDetail = false
    }
    // detailFn: function (item) {
    //   this.wllzid = item.wllzid
    //   this.dialogBackDetail = true
    // },
    // dialogBackCloseFn: function () {
    //   this.wllzid = ''
    //   this.dialogBackDetail = false
    // }
  },
  components: {
    // backDetail,
    synthesizeDetail
  },
  created: function () {}
}
</script>
